package org.ggumm21.moneybook;

import javax.persistence.Id;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.Parent;

//@Cached
public class AccountStatsByMonth {

	@SuppressWarnings("unused")
	@Id private Long id;
	private String methodName;
	private String ym;
	private double sum;
	private long cnt;
	@Parent private Key<AccountCategoryType> cateTypeKey;
	private AccountCategoryType.CATE_TYPE cateType;
	private long cateId;
	
	@SuppressWarnings("unused")
	private AccountStatsByMonth() {		
	}
	
	public AccountStatsByMonth(AccountCategory cate, String methodName, String ym) {
		this.ym = ym;
		this.cateTypeKey = new Key<AccountCategoryType>(AccountCategoryType.class, cate.getCateTypeId());
		this.cateType = cate.getCateType();
		this.cateId = cate.getId();
		this.methodName = methodName;
		this.sum = 0;
		this.cnt = 0;
	}
	
	public long getId() {
		return id;
	}
	
	public String getMethodName() {
		return methodName;
	}
	
	public String getYm() {
		return ym;
	}
	
	public double getSum() {
		return sum;		
	}
	
	public void clear() {
		sum = 0;
		cnt = 0;
	}
	
	public void apply(double amt, boolean isCancel) {
		this.sum += amt;
		if (isCancel) cnt--;
		else cnt++;
	}
	
	public AccountCategoryType.CATE_TYPE getCateType() {
		return this.cateType;
	}
	
	public long getCateTypeId() {
		return this.cateTypeKey.getId();
	}
	
	public long getCateId() {
		return this.cateId;
	}
	
}
